import Vuex from 'vuex';
import Vue from 'vue';

Vue.use(Vuex);


class Environment extends Vuex.Store {
  name = null;

  constructor(options) {
    super(options)
    if (options.hasOwnProperty('name')) {
      this.name = options['name'];
    }
  }
}

class EnvironmentManager extends Vuex.Store {
  modules = {};

  use(name) {
    return this.modules[name];
  }

  registerEnvironment(name, environment) {
    this.registerModule(name, environment);
    this.modules[name] = environment;
  }
}

const environmentManager = new EnvironmentManager();

Vue.use({
  install: function (Vue, options) {
    Vue.mixin({
      beforeCreate: function () {
        if (this.$options.environments) {
          Vue.prototype.$environments = this.$options.environments;
        }
      }
    })
  }
});
export default environmentManager;
export {
  Environment
}
